package com.ruoyi.wms.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.wms.mapper.WmsOutboundRecordMapper;
import com.ruoyi.wms.domain.WmsOutboundRecord;
import com.ruoyi.wms.service.IWmsOutboundRecordService;

/**
 * 出库记录Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-01-01
 */
@Service
public class WmsOutboundRecordServiceImpl implements IWmsOutboundRecordService 
{
    @Autowired
    private WmsOutboundRecordMapper wmsOutboundRecordMapper;

    /**
     * 查询出库记录
     * 
     * @param recordId 出库记录主键
     * @return 出库记录
     */
    @Override
    public WmsOutboundRecord selectWmsOutboundRecordById(Long recordId)
    {
        return wmsOutboundRecordMapper.selectWmsOutboundRecordById(recordId);
    }

    /**
     * 查询出库记录列表
     * 
     * @param wmsOutboundRecord 出库记录
     * @return 出库记录
     */
    @Override
    public List<WmsOutboundRecord> selectWmsOutboundRecordList(WmsOutboundRecord wmsOutboundRecord)
    {
        // 设置租户ID
        wmsOutboundRecord.setTenantId(SecurityUtils.getTenantId());
        return wmsOutboundRecordMapper.selectWmsOutboundRecordList(wmsOutboundRecord);
    }

    /**
     * 根据出库单ID查询出库记录列表
     * 
     * @param orderId 出库单ID
     * @return 出库记录集合
     */
    @Override
    public List<WmsOutboundRecord> selectWmsOutboundRecordByOrderId(Long orderId)
    {
        return wmsOutboundRecordMapper.selectWmsOutboundRecordByOrderId(orderId);
    }

    /**
     * 根据明细ID查询出库记录列表
     * 
     * @param detailId 出库单明细ID
     * @return 出库记录集合
     */
    @Override
    public List<WmsOutboundRecord> selectWmsOutboundRecordByDetailId(Long detailId)
    {
        return wmsOutboundRecordMapper.selectWmsOutboundRecordByDetailId(detailId);
    }

    /**
     * 根据分配ID查询出库记录列表
     * 
     * @param allocationId 库存分配ID
     * @return 出库记录集合
     */
    @Override
    public List<WmsOutboundRecord> selectWmsOutboundRecordByAllocationId(Long allocationId)
    {
        return wmsOutboundRecordMapper.selectWmsOutboundRecordByAllocationId(allocationId);
    }

    /**
     * 新增出库记录
     * 
     * @param wmsOutboundRecord 出库记录
     * @return 结果
     */
    @Override
    public int insertWmsOutboundRecord(WmsOutboundRecord wmsOutboundRecord)
    {
        // 设置租户ID和创建信息
        wmsOutboundRecord.setTenantId(SecurityUtils.getTenantId());
        wmsOutboundRecord.setCreateBy(SecurityUtils.getUsername());
        wmsOutboundRecord.setCreateTime(DateUtils.getNowDate());
        return wmsOutboundRecordMapper.insertWmsOutboundRecord(wmsOutboundRecord);
    }

    /**
     * 修改出库记录
     * 
     * @param wmsOutboundRecord 出库记录
     * @return 结果
     */
    @Override
    public int updateWmsOutboundRecord(WmsOutboundRecord wmsOutboundRecord)
    {
        wmsOutboundRecord.setUpdateBy(SecurityUtils.getUsername());
        wmsOutboundRecord.setUpdateTime(DateUtils.getNowDate());
        return wmsOutboundRecordMapper.updateWmsOutboundRecord(wmsOutboundRecord);
    }

    /**
     * 批量删除出库记录
     * 
     * @param recordIds 需要删除的出库记录主键
     * @return 结果
     */
    @Override
    public int deleteWmsOutboundRecordByIds(Long[] recordIds)
    {
        return wmsOutboundRecordMapper.deleteWmsOutboundRecordByIds(recordIds);
    }

    /**
     * 删除出库记录信息
     * 
     * @param recordId 出库记录主键
     * @return 结果
     */
    @Override
    public int deleteWmsOutboundRecordById(Long recordId)
    {
        return wmsOutboundRecordMapper.deleteWmsOutboundRecordById(recordId);
    }

    /**
     * 批量新增出库记录
     * 
     * @param recordList 出库记录列表
     * @return 结果
     */
    @Override
    public int batchInsertWmsOutboundRecord(List<WmsOutboundRecord> recordList)
    {
        if (recordList == null || recordList.isEmpty()) {
            return 0;
        }
        
        // 设置租户ID和创建信息
        for (WmsOutboundRecord record : recordList) {
            record.setTenantId(SecurityUtils.getTenantId());
            record.setCreateBy(SecurityUtils.getUsername());
            record.setCreateTime(DateUtils.getNowDate());
        }
        
        return wmsOutboundRecordMapper.batchInsertWmsOutboundRecord(recordList);
    }
}